#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define filename "log.txt"

int main()
{
    close(1);
    int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    if (fd < 0)
        perror("open");
    else
    {
        const char* str = "hello world\n";
        printf("fd = %d\n", fd);
        write(fd, str, strlen(str));
        printf("hello printf\n");
    }
    return 0;
}
